package ptij.ADSL.pn;

import ptolemy.kernel.util.*;
import ptolemy.actor.*;
import ptolemy.data.*;
import ptolemy.domains.pn.kernel.*;
import ptolemy.domains.pn.gui.PNApplet;

import ptij.ADSL.pn.ATUC.ATUC;
import ptij.ADSL.pn.ATUR.ATUR;

import java.awt.BorderLayout;

public class ADSL extends PNApplet {

    public void start() {
    
    }

    public void init() {
        super.init();
	try {
            _toplevel.setName("ADSL-PN");        	    

            BroadBandNetTx bnetTx = new BroadBandNetTx(_toplevel, "bnetTx");
	    bnetTx.AS0_Rate.setToken(new IntToken(1));
	    bnetTx.LS0_Rate.setToken(new IntToken(1));
	    bnetTx.endTime.setExpression("100000.0");
	    
	    BroadBandNetRx bnetRx = new BroadBandNetRx(_toplevel, "bnetRx");
	    
            ATUC atuc = new ATUC(_toplevel, "ATUC");
	    ATUR atur = new ATUR(_toplevel, "ATUR");

            CustomerNetTx cnetTx = new CustomerNetTx(_toplevel, "CustomerNetTx");
	    CustomerNetRx cnetRx = new CustomerNetRx(_toplevel, "CustomerNetRx");
	    	    
	    _toplevel.connect(bnetTx.AS0, atuc.AS0);
	    _toplevel.connect(bnetTx.LS0, atuc.LS0_in);
	    _toplevel.connect(bnetTx.dataTx, atuc.dataTx);
	    _toplevel.connect(atuc.LS0_out, bnetRx.LS0);
	    _toplevel.connect(atuc.dataRx, bnetRx.dataRx);

	    _toplevel.connect(atuc.tx, atur.rx);
	    _toplevel.connect(atur.tx, atuc.rx);

	    _toplevel.connect(atur.AS0, cnetRx.AS0);
	    _toplevel.connect(atur.LS0_out, cnetRx.LS0);
	    _toplevel.connect(atur.dataRx, cnetRx.dataRx);
	    _toplevel.connect(cnetTx.LS0, atur.LS0_in);
	    _toplevel.connect(cnetTx.dataTx, atur.dataTx);
	}
	catch(Exception ex) { 
	    report("Error constructing model.", ex);
	}
	getContentPane().add(_createRunControls(2), BorderLayout.SOUTH);
    }

    public static void main(String [] arg) throws IllegalActionException,
        NameDuplicationException {

            TypedCompositeActor _toplevel = new TypedCompositeActor();
            _toplevel.setName("toplevel");
            TimedPNDirector director = new TimedPNDirector(_toplevel, "director");
	    
	    Manager exec = new Manager("exec");
	    _toplevel.setManager(exec);

            BroadBandNetTx bnetTx = new BroadBandNetTx(_toplevel, "bnetTx");
	    bnetTx.AS0_Rate.setToken(new IntToken(1));
	    bnetTx.LS0_Rate.setToken(new IntToken(1));
	    bnetTx.endTime.setExpression("100000.0");
	    
	    BroadBandNetRx bnetRx = new BroadBandNetRx(_toplevel, "bnetRx");
	    
            ATUC atuc = new ATUC(_toplevel, "ATUC");
	    ATUR atur = new ATUR(_toplevel, "ATUR");

            CustomerNetTx cnetTx = new CustomerNetTx(_toplevel, "CustomerNetTx");
	    CustomerNetRx cnetRx = new CustomerNetRx(_toplevel, "CustomerNetRx");
	    	    
	    _toplevel.connect(bnetTx.AS0, atuc.AS0);
	    _toplevel.connect(bnetTx.LS0, atuc.LS0_in);
	    _toplevel.connect(bnetTx.dataTx, atuc.dataTx);
	    _toplevel.connect(atuc.LS0_out, bnetRx.LS0);
	    _toplevel.connect(atuc.dataRx, bnetRx.dataRx);

	    _toplevel.connect(atuc.tx, atur.rx);
	    _toplevel.connect(atur.tx, atuc.rx);

	    _toplevel.connect(atur.AS0, cnetRx.AS0);
	    _toplevel.connect(atur.LS0_out, cnetRx.LS0);
	    _toplevel.connect(atur.dataRx, cnetRx.dataRx);
	    _toplevel.connect(cnetTx.LS0, atur.LS0_in);
	    _toplevel.connect(cnetTx.dataTx, atur.dataTx);

            exec.run();
            return;
    }
}
